package com.jxpanda.infrastructure.crypto.key;

import com.jxpanda.infrastructure.crypto.constant.AlgorithmEncrypt;
import com.jxpanda.infrastructure.crypto.key.contract.AbstractKeyProvider;
import com.jxpanda.infrastructure.crypto.key.contract.KeyPairProvider;

import java.security.KeyPair;
import java.security.spec.RSAKeyGenParameterSpec;

public class RsaKeyPairProvider extends AbstractKeyProvider<KeyPair, RSAKeyGenParameterSpec> implements KeyPairProvider<RSAKeyGenParameterSpec> {


    public RsaKeyPairProvider() {
        super(AlgorithmEncrypt.RSA.KEY_ALGORITHM);
    }

    @Override
    public KeyPair generateKey() {
        return generateKey(createAlgorithmParameterSpec());
    }

    public static RSAKeyGenParameterSpec createAlgorithmParameterSpec() {
        return createAlgorithmParameterSpec(AlgorithmEncrypt.RSA.KEY_BITS_2048);
    }

    public static RSAKeyGenParameterSpec createAlgorithmParameterSpec(int keyBits) {
        return new RSAKeyGenParameterSpec(keyBits, RSAKeyGenParameterSpec.F4);
    }

}
